﻿$(document).ready(function () {

    if ($("#result").html() == "添加成功" || $("#result").html() == "修改成功") {
        //关闭当前对话框并刷新父页面
        $(window.top.document).find("#searchBtn").click();
        window.top.art.dialog.get('operationmanagecontractcreate').close();
    }

    $("#selectParentUnit").click(function () {
        var url = "/Contract/PickParentUnit" + "?unitId=" + $("#ParentUnitID").val();
        artDialogForm(url, "选择所属单位", "operationmanageusercreatepickparent", 400, 300);
    });

    $("#selectClient").click(function () {
        var url = "/Contract/PickClient" + "?unitId=" + $("#ParentUnitID").val();
        artDialogForm(url, "选择合作客户", "operationmanageusercreatepickclient", 400, 300);
    });

    var validator = $("#contractcreateform").validate({
        errorPlacement: function (error, element) {
            error.appendTo(element.parent());
        },
        rules: {
            WorkSiteName:
            {
                required: true,
                maxlength: 50
            },
            InnerId:
            {
                required: true,
                maxlength: 50
            },
            WorkSiteName:
            {
                required: true,
                maxlength: 50
            },
            ContractName:
            {
                required: true,
                maxlength: 50
            },
            ParentUnitId:
            {
                required: true
            },
            ContactPeople:
            {
                maxlength: 50
            },
            ContactTel:
            {
                maxlength: 50
            },
            Fmemo:
            {
                maxlength: 255
            }
        }
        //onfocusout: function(element) { $(element).valid(); }
    });

    $("#submitBtn").click(function () {
        if (validator.form()) {
            $("#contractcreateform").submit();
        }
    });
});